package com.yoyo.itravel.dao;
import com.yoyo.itravel.bean.City;
import com.yoyo.itravel.bean.PageBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

/**
 * @Description 城市表相关操作接口【持久层】
 *
 * @author HZX
 * @date 2020/5/8 23:18
 */
@Repository
public interface ICityDao {
	/**
	 * 得到所有的city信息
	 * 
	 * @return
	 * @throws SQLException
	 */
	@Select("select * from tb_city")
	List<City> selectAll() throws SQLException;

	/**
	 * 得到对应省份的所有城市列表信息
	 * 
	 * @param provinceId
	 * @return
	 * @throws SQLException
	 */
	@Select("select * from tb_city where provinceId=#{provinceId}")
	List<City> selectByProvinceId(String provinceId) throws SQLException;

	/**
	 * 插入城市信息
	 * 
	 * @param city
	 * @return
	 * @throws SQLException
	 */
	@Insert("insert into tb_city(cityId,cityName,provinceId) values(#{cityId},#{cityName},#{provinceId})")
	int insert(City city) throws SQLException;

	/**
	 * 插入城市名称查找城市信息
	 *
	 * @param cityName
	 * @return
	 * @throws SQLException
	 */
	@Select("select * from tb_city where cityName=#{cityName}")
	City selectByName(String cityName) throws SQLException;

	/**
	 * @Description 通过城市id获得城市对象
	 *
	 * @param cityId
	 * @return cn.hut.travel.bean.City
	 */
	@Select("select * from tb_city where cityId=#{cityId}")
    City selectByCityId(String cityId) throws SQLException;

	@Select("select * from tb_city limit #{startPage},#{pageSize}")
    List<City> selectCityByPage(PageBean page) throws SQLException;

	/**
	 * 查询所有城市数量
	 * @return
	 * @throws SQLException
	 */
	@Select("select count(*) from tb_city")
	Integer totalCount() throws SQLException;
}
